<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-20 21:41:37
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-11-07 22:37:15
 * @Descripttion: 系统配置
 */

namespace app\api\controller\user\v1_0\bus;



class Index extends \app\api\controller\user\v1_0\Common
{
    protected $noNeedRight = ['test'];
    /**
     * @Author: 哲学家乔布斯 <wuyangii@qq.com>
     * @brief: 
     * @return 
     * @Descripttion: 首页默认接口
     */    
    public function index(){
        $param = request()->param();
        $page = empty(request()->param('page')) ? 1 : request()->param('page');
        $limit = empty(request()->param('limit')) ? 10 : request()->param('limit');
        $where = [];
    
     
        $user = (new \app\common\model\User())->where(['id' => $this->UserInfo['id']])->find();
        $bus = (new \app\common\model\Bus())->where(['id' => $user['bus_id']])->find();
        if(empty($bus)){
            return self::errorResult("当前用户暂未开启该功能");
        }
        if($param['type'] == 0){
            $where['state'] = 1;
         }else{
            $where['state'] = 2;
         }
         $order = (new \app\common\model\BusOrder())
                     ->where(['bus_id' => $bus['id']])
                     ->append(['state_text','addtime_text'])
                     ->where($where)
                     ->page($page)
                     ->limit($limit)
                     ->select();
        return self::successResult("成功",[
            'money' => [
                'bus_smoney' => $bus['money'],
            ],
            'order' => $order,
        ]);
    }
    public function info(){
        $id = request()->param('id');
        $order = (new \app\common\model\BusOrder())->where(['id' => $id])->find();
        $info = (new \app\common\model\UserOrders())
                    ->alias("order")
                    ->join("{$this->tdb}user_orders_goods order_goods","order_goods.order_id = order.id")
                    ->where(['order.bus_order_id' => $order['id']])
                    ->append([
                        'addtime_text','state_text','driver_q_title','driver_title',
                        'driver_q_state_text','driver_state_text','bus_state_text','goods_info'
                        ])
                    ->select();
        return self::successResult("成功",[
            'info' => $info,
            'order' => $order
        ]);
    }
    public function bus_money_log(){
        $page = empty(request()->param('page')) ? 1 : request()->param('page');
        $limit = empty(request()->param('limit')) ? 10 : request()->param('limit');
        $where = [];
     
        $user = (new \app\common\model\User())->where(['id' => $this->UserInfo['id']])->find();
        $bus = (new \app\common\model\Bus())->where(['id' => $user['bus_id']])->find();
        if(empty($bus)){
            return self::errorResult("当前用户暂未开启该功能");
        }
         $order = (new \app\common\model\BusMoneyLog())
                     ->where(['bus_id' => $bus['id']])
                     ->append(['addtime_text'])
                     ->where(['type' => 0])
                     ->page($page)
                     ->limit($limit)
                     ->select();
        return self::successResult("成功",[
            'order' => $order,
        ]);
    }
    
    

}
